import java.io.*;
import java.security.NoSuchAlgorithmException;
import javax.crypto.*;
public class Skey_DES{ //生成伪随机的密钥
    public static void main(String args[]) throws Exception{
        KeyGenerator kg= null;
        try {
            kg = KeyGenerator.getInstance("DES");
        } catch (NoSuchAlgorithmException e) {
            System.out.println("密钥生成错误！");
            e.printStackTrace();
        }
        kg.init(56);
        SecretKey k=kg.generateKey( );
        FileOutputStream  f=new FileOutputStream("key1.dat");
        ObjectOutputStream b=new  ObjectOutputStream(f);
        b.writeObject(k);
    }
}